var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__spreadArrays) ||
        function () {
            for (var t = 0, e = 0, o = arguments.length; e < o; e++) t += arguments[e].length;
            var n = Array(t),
                r = 0;
            for (e = 0; e < o; e++) for (var a = arguments[e], i = 0, s = a.length; i < s; i++, r++) n[r] = a[i];
            return n;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("AdCtrl"),
    i = t("NativeAdIcon"),
    s = t("Platforms"),
    c = t("Sounds"),
    l = (function (t) {
        function e(e, o, n) {
            for (var a = [], l = 3; l < arguments.length; l++) a[l - 3] = arguments[l];
            var u = t.call(this) || this;
            return (
                (u._onLoaded = function (t) {
                    if (((u.currInfo = null), t && t.adList && t.adList.length)) {
                        u.infos.length = 0;
                        for (var e = 0, o = t.adList; e < o.length; e++) {
                            var n = o[e];
                            u.infos.push(n);
                        }
                        u.loadNextImg();
                    }
                    u.status = "加载成功";
                }),
                (u._onError = function (t) {
                    u.log(JSON.stringify(t), !0), (u.status = "出错");
                }),
                u.init.apply(u, r([e, o, n], a)) &&
                    ((u.infos = new Array()),
                    (u.icon = s.default.prefabs.instantiate("NativeAdIcon").getComponent(i.default)),
                    u.icon.init(),
                    u.icon.node.on(cc.Node.EventType.TOUCH_END, function () {
                        c.Sounds.playFX("点击"), u.ad.reportAdClick({adId: u.currInfo.adId});
                    }),
                    (u.icon.node.active = !1),
                    u.create()),
                u
            );
        }
        return (
            n(e, t),
            (e.prototype.加载中 = function () {
                return "加载中" == this.status;
            }),
            (e.prototype.可显示 = function () {
                return this.ad && "加载成功" == this.status;
            }),
            (e.prototype.clear = function () {
                this.ad &&
                    (this.ad.offLoad && this.ad.offLoad(this._onLoaded),
                    this.ad.offError && this.ad.offError(this._onError),
                    this.ad.destroy && this.ad.destroy(),
                    (this.ad = null));
            }),
            (e.prototype.create = function () {
                this.clear(),
                    this._createAd() &&
                        ((this.剩余展示次数 = this._同一内容展示次数 = this.同一内容展示次数()),
                        (this._同一内容展示时间 = this.同一内容展示时间()),
                        (this.开始加载时间 = new Date().getTime()),
                        this.ad.onLoad && this.ad.onLoad(this._onLoaded),
                        this.ad.onError && this.ad.onError(this._onError),
                        (this.status = "加载中"),
                        this.初始手动加载 && this.load());
            }),
            (e.prototype.load = function () {
                this.ad && this.ad.load();
            }),
            (e.prototype.show = function (t, e) {
                var o;
                if (this.rule) this.log("重复展示 " + this.rule.名称, !0);
                else if (((this.rule = t), this.currInfo))
                    this.icon.node.active ||
                        ((this.icon.node.active = !0),
                        this.rule.target.addChild(this.icon.node),
                        (o = s.default.getPos(this.rule, this.rule.target, 100, 132, 50, -50)),
                        (this.icon.node.x = o[0]),
                        (this.icon.node.y = o[1]),
                        this.ad.reportAdShow({adId: this.currInfo.adId})),
                        e && e(!0);
                else {
                    if ((this.加载中() && this.检查超时(), this.加载中()));
                    else {
                        if (!this.检查广告出错再次尝试时间()) return void (e && e(!1));
                        this.load();
                    }
                    e && e(!1);
                }
            }),
            (e.prototype.hide = function () {
                this.rule
                    ? (this.icon.node.active &&
                          (this.icon.node.parent.removeChild(this.icon.node, !1),
                          (this.icon.node.active = !1),
                          this.infos.length &&
                              this.展示次数或展示时间达到预定值() &&
                              (this.infos.shift(), this.infos.length ? this.loadNextImg() : this.load())),
                      (this.rule = null))
                    : this.log("木有展示", !0);
            }),
            (e.prototype.loadNextImg = function () {
                (this.currInfo = this.infos[0]), this.icon.set(this.currInfo);
            }),
            e
        );
    })(a.default);
o.default = l;
